package factory;

import interactions.Interaction;
import java.awt.List;
import java.io.File;
import java.io.FileNotFoundException;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Scanner;

import sprite.Sprite;
import updater.InteractionUpdater;
import updater.SpriteUpdater;
import updater.WinLossStateUpdater;
import winStrategies.WinLossStrategy;

/**
 * @author guytracy
 * Abstract factory class that allows for extendable subclass factories.
 * Can be extended by adding and addObject method that parses individual scanner lines 
 * to create objects. Must also add a get or set method that returns or sets the product. This calls loadObjects
 */
public abstract class AbstractFactory {
    
    protected static final String BEHAVIOR_LOCATION = "spritebehavior.";
    protected static final String IMAGE_LOCATION = "images/";
    protected static final String REACTION_LOCATION = "interactions.";
    
    /**
     * blank constructor
     */
    public AbstractFactory() {
      
    }
    
    /**
     * @param line
     * @throws ClassNotFoundException
     * @throws InstantiationException
     * @throws IllegalAccessException
     * 
     * addObject must be different for each subclass, as the parsing is different
     */
    protected abstract void addObject(Scanner line) throws ClassNotFoundException, InstantiationException, IllegalAccessException;

    /**
     * loads the file and creates and object for each line
     * @param levelFile
     */
    protected void loadObjects(File levelFile) {
        try {
            Scanner input = new Scanner(levelFile);
            while (input.hasNext()) {
                Scanner line = new Scanner(input.nextLine());
                if (line.hasNext()) {
                    addObject(line);
                }
            }
            input.close();

        }
        catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        catch (ClassNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        catch (InstantiationException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        catch (IllegalAccessException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

}
